package com.ruoyi.interview.controller;

import java.util.*;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.common.core.domain.R;
import com.ruoyi.interview.domain.*;
import com.ruoyi.interview.domain.vo.CorporationVo;
import com.ruoyi.interview.domain.vo.LoginVo;
import com.ruoyi.interview.domain.vo.TbStudentVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.interview.service.ITbInterviewService;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.page.TableDataInfo;

/**
 * 面试明细Controller
 * 
 * @author ruoyi
 * @date 2024-05-27
 */
@RestController
@RequestMapping("/interview")
public class TbInterviewController extends BaseController
{
    @Autowired
    private ITbInterviewService tbInterviewService;

    /**
     * 查询面试明细列表
     */


    @GetMapping("/list")
    public TableDataInfo list(TbRecords tbRecords)
    {
       List<TbRecords> list  =  tbInterviewService.selectTbRecordsList(tbRecords);
        return getDataTable(list);
    }

    /**
     * 导出面试明细列表
     */


    @PostMapping("/export")
    public void export(HttpServletResponse response, TbInterview tbInterview)
    {
        List<TbInterview> list = tbInterviewService.selectTbInterviewList(tbInterview);
        ExcelUtil<TbInterview> util = new ExcelUtil<TbInterview>(TbInterview.class);
        util.exportExcel(response, list, "面试明细数据");
    }

    /**
     * 获取面试明细详细信息
     */

    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(tbInterviewService.selectTbInterviewById(id));
    }

    /**
     * 新增面试明细
     */

    @Log(title = "面试明细", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TbRecords tbRecords  )
    {
        return toAjax(tbInterviewService.insertTbInterview(tbRecords));
    }

    /**
     * 修改面试明细
     */

    @Log(title = "面试明细", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TbRecords tbRecords )
    {
        return toAjax(tbInterviewService.updateTbInterview(tbRecords));
    }

    /**
     * 删除面试明细
     */

    @Log(title = "面试明细", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long ids)
    {
        return toAjax(tbInterviewService.deleteTbInterviewById(ids));
    }



    @PostMapping("/interviewLogin")
    public R interviewLogin(@RequestBody LoginVo loginVo)
    {

        return   tbInterviewService.interviewLogin(loginVo);
    }


    @PostMapping("/findCorporation")
    public Set<CorporationVo> findCorporation()
    {
       List<TbCorporation> corporations = tbInterviewService.findCorporation();
        Set<CorporationVo> list = new HashSet<>();
        for (TbCorporation corporation : corporations) {

            if (corporation.getCorporationName()!=null){

                list.add(new CorporationVo(corporation.getCorporationName()));
            }
        }
        return list;
    }

    @PostMapping("/findCorporationAddress")
    public Set<CorporationVo> findCorporationAddress()
    {
        List<TbCorporation> corporations = tbInterviewService.findCorporation();
        Set<CorporationVo> list = new HashSet<>();
        for (TbCorporation corporation : corporations) {

            if (corporation.getCorporationName()!=null){

                list.add(new CorporationVo(corporation.getCorporationAddress()));
            }
        }
        return list;
    }


    @PostMapping("/findPost")
    public Set<CorporationVo> findPost()
    {
        List<TbPost> corporations = tbInterviewService.findPost();
        Set<CorporationVo> list = new HashSet<>();
        for (TbPost post : corporations) {

            if (post.getPostName()!=null){

                list.add(new CorporationVo( post.getPostName()));
            }
        }
        return list;
    }


    @PostMapping("/findInfo")
    public Set<CorporationVo> findInfo()
    {
        List<TbRecords> corporations = tbInterviewService.selectInfoList();
        Set<CorporationVo> list = new HashSet<>();
        for (TbRecords records : corporations) {

            if (records.getStuName()!=null){
                list.add(new CorporationVo( records.getStuName()));
            }
            if (records.getCorporationName()!=null){
                list.add(new CorporationVo( records.getCorporationName()));
            }
            if (records.getPostName()!=null){
                list.add(new CorporationVo( records.getPostName()));
            }
            if (records.getCorporationAddress()!=null){
                list.add(new CorporationVo( records.getCorporationAddress()));
            }
        }
        return list;
    }

    @PostMapping("/saveComment")
    public AjaxResult saveComment(@RequestBody TbComment tbComment)
    {
       tbComment.setCreatedTime(new Date());
        return toAjax(tbInterviewService.saveComment(tbComment));
    }
}
